import java.io.File;
import java.io.IOException;

public class DocumentOne {
    File f = new File("D:\\");  //创建一个指向D盘的根目录文件
    //更改目录
    public void changeDir(String newDir){   //返回上一级文件目录
    if("..".equals(newDir)){
        f = f.getParentFile();
                System.out.println("返回上一级成功！");
            System.out.println(f);
        }
    else{
        String oldDir = f.getAbsolutePath();
        File ftemp = new File(oldDir + "\\" + newDir);
        System.out.println("更改成功！");
            System.out.println(ftemp);
        }
    }

    //删除目录
    public void deleteDir(String dir) {
        String oldDir = f.getAbsolutePath();
        File ftemp = new File((oldDir + "\\") + dir);
            System.out.println(ftemp.getAbsolutePath());
            ftemp.delete();
            System.out.println("删除成功！");
        System.out.println(ftemp);
        }


    //新建文件
    public void creatDoc(String newDoc) {
        String oldDir = f.getAbsolutePath();
        File ftemp = new File(oldDir + "\\" + newDoc);
            try {
                ftemp.createNewFile();
                System.out.println("创建成功，请在D盘文件夹下查看！");
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

    //创建目录
    public void addDirs(String newDir) {
        String oldDir = f.getPath();
        File ftemp = new File((oldDir + "\\") + newDir);
        ftemp.mkdirs();
        System.out.println("多级目录创建成功，请在D盘查看！");
    }

    //删除文件
    public void delDoc(String doc) {
        String oldDir = f.getAbsolutePath();
        File ftemp = new File((oldDir + "\\") + doc);
            ftemp.delete();
            System.out.println("删除成功！");
    }

    //显示目录
    public void displayDir(String dir){
        File f = new File("D:\\");
        File[] tempList = f.listFiles();
            for(int i=0;i<tempList.length;i++) {
                if (tempList[i].isDirectory()){
                    System.out.println("文件夹：" +tempList[i]);
                }
            }
    }

    //获取指令
    public void obtainAllOrder(){
        System.out.println("改变目录：cd 目录名");
        System.out.println("显示目录：dir 目录名");
        System.out.println("创建一级目录：md1 目录名");
        System.out.println("创建多级目录：mds 目录名");
        System.out.println("删除目录：rd 目录名");
        System.out.println("新建文件：edit 文件名");
        System.out.println("删除文件：del 文件名");
        System.out.println("获得所有指令：help");
        System.out.println("退出文件系统：exit");
    }
}
